﻿using LJ.Abstractions.Pack;
using LJ.Logging.Serilog.Pack;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Serilog;
using Serilog.Events;

namespace LJ.Logging.Serilog.File.Pack;

public class LoggingSerilogFilePackBase : AspNetCorePackBase,ILoggingSerilogPackBase
{

    public override void Add(IAspNetCorePackContext aspNetCorePackContext)
    {
        Log.Logger = new LoggerConfiguration()
#if DEBUG
      .MinimumLevel.Debug()
#else
                .MinimumLevel.Information()
#endif
      .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
      .Enrich.FromLogContext()
      .WriteTo.Async(c => c.File($"Logs/{DateTime.Now:yyyy-MM-dd}-log.txt"))
        .CreateLogger();

        aspNetCorePackContext.DependencyManager.ServiceCollection.AddSerilog();


        aspNetCorePackContext.DependencyManager.ServiceCollection.AddSingleton<IPackProcessingServer, LoggingSerilogPackProcessingServer>();
    }

    public override void Use(IAspNetCorePackProvider packProvider)
    {
        packProvider.ApplicationBuilder.UseSerilogRequestLogging();


    }
}
